import sys
from loguru import logger

from androguard.core.apk import APK

# 移除所有默认的配置
logger.remove()
# 将日志记录到控制台，并设置级别为 WARNING
logger.add(sys.stdout, level="WARNING")


def get_package_name(apk_file_path):
    """
    获取当前包名信息
    :param apk_file_path: apk文件
    :return: 包名：com.youzu.ss0.baidu
    """
    try:
        a = APK(apk_file_path)
        package_name = a.get_package()
        return package_name
    except Exception as e:
        print(f"获取包名出错: {e}")
        return None


if __name__ == '__main__':
    print(get_package_name(r"D:\system\Desktop\airtest_apk\baidusearch_AndroidPhone_1037068k.apk"))
